//
//  directSeedingViewController.m
//  MagicBox
//
//  Created by dllo on 16/8/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "directSeedingViewController.h"
#import "Dire_Model.h"
#import "Dire_TableviewCell.h"
#import "Dire_SendViewController.h"
#import "Dire_ThreeViewController.h"

@interface directSeedingViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, retain) UITableView *tableview;
@property (nonatomic, retain) NSMutableArray *muarray;
@property (nonatomic, retain) NSMutableArray *mmarray;


@end

@implementation directSeedingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.navigationItem.title = @"CCTV";
    self.muarray = [NSMutableArray array];
    self.mmarray = [NSMutableArray array];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"开始直播" style:UIBarButtonItemStylePlain target:self action:@selector(button:)];
    self.tableview = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_tableview];
    self.tableview.dataSource = self;
    self.tableview.delegate = self;
    self.tableview.rowHeight = SCREENHEIGHT/3*2;
    [self.tableview registerClass:[Dire_TableviewCell class] forCellReuseIdentifier:@"cell"];
    [self.tableview registerClass:[Dire_TableviewCell class] forCellReuseIdentifier:@"cell1"];
    [self creactNumber];

   


}
-(void)creactNumber{
    
    [CCNetTool GET:@"http://service.ingkee.com/api/live/simpleall?&devi=6a6fe028d0dd1e0c49018ecb7d4a9e02f34b8f8a&cv=IK3.3.00_Iphone&ua=iPhone7_2&proto=7&lc=0000000000000032&idfv=BA52F8A1-24C2-4AC8-BDAA-4932F938D975&imsi=&imei=&cc=TG0001&osversion=ios_9.200000&idfa=D35EAB73-3F60-473C-8581-DD8CEC9FBAE9&uid=83390870&sid=20HGlzoO65o65Dnuc2SceEi12Wi0mMDei1p0Fpo8E18ca0ABavc8i3&conn=Wifi&s_sg=d8649a9e33f724408d981e0d31337adb&s_sc=100&s_st=1471226302&" body:nil headerFile:nil response:CCJSON success:^(id result) {
        NSArray *lives = [result objectForKey:@"lives"];
    
        for(NSDictionary *dic in lives){
            Dire_Model *model = [[Dire_Model alloc]initWithDic:dic];
            [self.muarray addObject:model];
            NSDictionary *creator = [dic objectForKey:@"creator"];
            Dire_Model *model1 = [[Dire_Model alloc]initWithDic:creator];
            [self.mmarray addObject:model1];
//            NSLog(@"%@",model1.portrait);
         
        }
        [self.tableview reloadData];
        
        
        
        
    } failure:^(NSError *error) {
//        NSLog(@"%@",error);
    }];
    
    
    
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.mmarray.count+1;
    
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        Dire_TableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
      
        return cell;
        
    }else{
    
    
    Dire_TableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.model = [self.muarray objectAtIndex:indexPath.row];
    cell.model1 = [self.mmarray objectAtIndex:indexPath.row];

    return cell;
    
    }
    return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
         Dire_SendViewController *dvc = [[Dire_SendViewController alloc]init];
        dvc.string = @"rtmp://live.hkstv.hk.lxdns.com:1935/live/Gao123";
        dvc.navigationController.navigationBar.hidden = YES;
         [self.navigationController pushViewController:dvc animated:YES];
    }else{
    Dire_SendViewController *dvc = [[Dire_SendViewController alloc]init];
    dvc.model = [self.muarray objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:dvc animated:YES];
        
 
    }

}
-(void)button:(UIButton*)but{
    Dire_ThreeViewController *dtvc = [[Dire_ThreeViewController alloc]init];
    [self.navigationController pushViewController:dtvc animated:YES];

}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
